package org.aeon.gamechatnest.service.impl;

import org.aeon.gamechatnest.dto.AuthoritySearchDto;
import org.aeon.gamechatnest.dto.AuthorityVo;
import org.aeon.gamechatnest.mapper.AuthorityMapper;
import org.aeon.gamechatnest.pojo.Role;
import org.aeon.gamechatnest.service.AuthorityService;
import org.aeon.gamechatnest.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: MissingAeon
 * @date: 2024/5/10 18:07
 * @description:
 */
@Service
public class AuthorityServiceImpl implements AuthorityService {
    @Autowired
    private AuthorityMapper authorityMapper;

    @Lazy
    @Autowired
    private RoleService roleService;

    @Override
    public List<String> findAuthoritiesCodeByRoleIds(List<Role> roles) {
        if (roles == null || roles.isEmpty()) return new ArrayList<>();
        return authorityMapper.getAuthorityCodeByRoleIds(roles);
    }

    @Override
    public List<AuthorityVo> find(AuthoritySearchDto authoritySearchDto) {
        return authorityMapper.get(authoritySearchDto);
    }

    @Override
    public List<AuthorityVo> findAuthorityByRoleId(Long roleId) {
        return authorityMapper.getByRoleId(roleId);
    }
}
